package com.boyi.shared.util.http.impl;

import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;

import java.io.IOException;

/**
 * @author 颜培轩
 * @date 2017年11月21日  上午 09:04
 */
public class ResponseHandler {
    private static Log logger = LogFactory.getLog(ResponseHandler.class);

    public static String toString(HttpResponse response) {
        if (response != null) {
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                try {
                    return IOUtils.toString(response.getEntity().getContent(), "UTF-8");
                } catch (IOException e) {
                    logger.error("IO异常");
                }
            } else {
                logger.error(response.getStatusLine().getStatusCode() + "  " + response.getStatusLine().getReasonPhrase());
            }
        }
        return null;
    }

   
}
